package local.sumw3.findmydevices.object.bean;

import java.util.Date;

import local.sumw3.json.JSONException;
import local.sumw3.json.JSONObject;


public class Location {

    private double horizontalAccuracy;

    private double longitude;

    private double latitude;

    private boolean locationFinished;

    private String positionType;

    private Date locationTimestamp;

    public double getHorizontalAccuracy() {
        return horizontalAccuracy;
    }

    public void setHorizontalAccuracy(double horizontalAccuracy) {
        this.horizontalAccuracy = horizontalAccuracy;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public boolean isLocationFinished() {
        return locationFinished;
    }

    public void setLocationFinished(boolean locationFinished) {
        this.locationFinished = locationFinished;
    }

    public String getPositionType() {
        return positionType;
    }

    public void setPositionType(String positionType) {
        this.positionType = positionType;
    }

    public Date getLocationTimestamp() {
        return locationTimestamp;
    }

    public void setLocationTimestamp(Date locationTimestamp) {
        this.locationTimestamp = locationTimestamp;
    }

    public static Location parseFromJSON(JSONObject jsonLoc) throws JSONException {
        Location loc = null;
        if (jsonLoc != null) {
            loc = new Location();
            loc.setHorizontalAccuracy(jsonLoc.getDouble("horizontalAccuracy"));
            loc.setLatitude(jsonLoc.getDouble("latitude"));
            loc.setLongitude(jsonLoc.getDouble("longitude"));
            loc.setLocationFinished(jsonLoc.getBoolean("locationFinished"));
            loc.setPositionType(jsonLoc.getString("positionType"));
            loc.setLocationTimestamp(new Date(jsonLoc.getLong("timeStamp")));
        }
        return loc;
    }
}
